package com.example.p2pinvest.util;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;

/**
 * @author h2tc01
 * @version 1.0.0
 * 2022/8/11
 */
public class DrawUtils {

    public static Drawable getDrawable(int rgb, float radius) {
        GradientDrawable drawable = new GradientDrawable();

        drawable.setColor(rgb);  //填充颜色
        drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);  //shape矩形
        drawable.setCornerRadius(radius);  //四周圆角半径
        drawable.setStroke(UIUtils.dp2px(1), rgb);  //边框厚度与颜色

        return drawable;
    }

    public static StateListDrawable getSelector(Drawable normalDrawable, Drawable pressDrawable) {
        StateListDrawable stateListDrawable = new StateListDrawable();
        //给当前的颜色选择器添加选中图片指向状态，未选中图片指向状态
        stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, pressDrawable);
        stateListDrawable.addState(new int[]{android.R.attr.state_enabled}, normalDrawable);
        //设置默认状态
        stateListDrawable.addState(new int[]{}, normalDrawable);
        return stateListDrawable;
    }
}
